package com.zzedu.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzWordBody;
import com.zzedu.dto.ZzWordBodyDTO;
import com.zzedu.service.IZzWordBodyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (教育-统计)文件内容Controller
 * 
 * @author Mr.Wang
 * @date 2025-03-16
 */
@RestController
@RequestMapping("/datacenter/filebody")
public class ZzWordBodyController extends BaseController
{
    @Autowired
    private IZzWordBodyService zzWordBodyService;

    /**
     * 查询(教育-统计)文件内容列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filebody:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzWordBodyDTO zzWordBody)
    {
        LambdaQueryWrapper<ZzWordBody> lambdaQueryWrapper= zzWordBodyService.buildQuery(zzWordBody);
        lambdaQueryWrapper.orderByDesc(ZzWordBody::getWordCount,ZzWordBody::getId);
        lambdaQueryWrapper.select(ZzWordBody::getId,ZzWordBody::getWordCount,ZzWordBody::getFileId,ZzWordBody::getWordContent);
        return getDataTable(zzWordBodyService.page(zzWordBody.getPageDTO(),lambdaQueryWrapper));
    }

    /**
     * 查询(教育-统计)文件内容列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filebody:query')")
    @RequestMapping("/listGroup")
    public TableDataInfo listGroup(@RequestBody ZzWordBodyDTO zzWordBody)
    {
        LambdaQueryWrapper<ZzWordBody> lambdaQueryWrapper= zzWordBodyService.buildQuery(zzWordBody);
        lambdaQueryWrapper.select(ZzWordBody::getWordContent,ZzWordBody::getSumCount);
        lambdaQueryWrapper.groupBy(ZzWordBody::getWordContent);
        lambdaQueryWrapper.orderByDesc(ZzWordBody::getSumCount,ZzWordBody::getWordContent);
        return getDataTable(zzWordBodyService.page(zzWordBody.getPageDTO(),lambdaQueryWrapper));
    }
    /**
     * 导出(教育-统计)文件内容列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filebody:export')")
    @Log(title = "(教育-统计)文件内容", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzWordBodyDTO zzWordBody)
    {
        List<ZzWordBody> list = zzWordBodyService.list(zzWordBodyService.buildQuery(zzWordBody));
        ExcelUtil<ZzWordBody> util = new ExcelUtil<ZzWordBody>(ZzWordBody.class);
        util.exportExcel(ServletUtils.getResponse(),list, "(教育-统计)文件内容数据");
    }




    /**
     * 新增保存(教育-统计)文件内容
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filebody:add')")
    @Log(title = "(教育-统计)文件内容", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzWordBody zzWordBody)
    {
        return toAjax(zzWordBodyService.save(zzWordBody));
    }



    /**
     * 获取(教育-统计)文件内容详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filebody:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zzWordBodyService.getById(id));
    }


    /**
     * 修改保存(教育-统计)文件内容
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filebody:edit')")
    @Log(title = "(教育-统计)文件内容", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzWordBody zzWordBody)
    {
        return toAjax(zzWordBodyService.updateById(zzWordBody));
    }

    /**
     * 删除(教育-统计)文件内容
     */
    @PreAuthorize("@permission.hasAnyPermissions('datacenter:filebody:remove')")
    @Log(title = "(教育-统计)文件内容", businessType = BusinessType.DELETE)
	@RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(zzWordBodyService.removeBatchByIds(ids));
    }
}
